package com.thortec.farmsys.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @auther ny by:dbw
 * @create 2018-06-27
 */
public class JsonUtils {

    public static String obj2JsonStr(Object obj){
        String s=null;
        if(obj!=null){
            s= JSON.toJSONString(obj);
        }
       return s;
    }

    public static Object jsonStr2Obj(String jsonStr,Class type){
        Object o=null;
        if(!StringUtils.isEmpty(jsonStr)&&type!=null){
           o = JSON.parseObject(jsonStr, type);
        }
        return o;
    }
    public static <T> List<T> jsonStr2List(String jsonStr, Class<T> type){
        List<T> o=null;
        if(!StringUtils.isEmpty(jsonStr)&&type!=null){
            o = JSONArray.parseArray(jsonStr, type);
        }
        return o;
    }
}
